package com.kongxr.opengltest.shape;

import android.opengl.GLES20;

import com.kongxr.opengltest.mygles.MyGlRender;

import java.lang.annotation.Native;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class Triangle {

    private final String vertexShaderCode =
            "attribute vec4 vPosition;" +
                    "void main() {" +
                    "  gl_Position = vPosition;" +
                    "}";

    private final String fragmentShaderCode =
            "precision mediump float;" +
                    "uniform vec4 vColor;" +
                    "void main() {" +
                    "  gl_FragColor = vColor;" +
                    "}";

    static final int COORDS_PER_VERTEX = 3;
    static float[]  triangleCoods = {
            0.0f, 0.62154554f, 0.0f,
            -0.5f, -0.323463543f, 0.0f,
            0.5f, -0.5514544566f, 0.0f
    };

    public Triangle() {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(triangleCoods.length * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
        floatBuffer.put(triangleCoods);
        floatBuffer.position(0);

        int vertexShader = MyGlRender.loadShader(GLES20.GL_SHADER_TYPE, vertexShaderCode);
        int fragmentShader = MyGlRender.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
        int program = GLES20.glCreateProgram();
        GLES20.glAttachShader(program, vertexShader);
        GLES20.glAttachShader(program, fragmentShader);

    }

}
